package org.calvados.study.webflux.endpoint;

import org.calvados.study.webflux.domain.User;
import org.calvados.study.webflux.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/user")
public class UserEndpoint {

    private UserService userService;

    @Autowired
    public void setUserService(UserService userService) {
        Assert.notNull(userService, "userService can not be null.");
        this.userService = userService;
    }

    @GetMapping(value = "/all", produces = MediaType.APPLICATION_STREAM_JSON_VALUE)
    public Flux<User> listAllUser() {
        return userService.listAllUser();
    }
}
